package com.vert.controller;

import com.alibaba.fastjson.JSONObject;
import com.vert.annotations.*;
import com.vert.auth.model.UserModel;
import com.vert.db.TableService;
import com.vert.utils.Results;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname UserController
 * @Description TODO
 * @Date 2022/5/30 12:52
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController("/user")
public class UserController {

    @Autowired
    private TableService tableService;

    @GetMapping("/user")
    public JSONObject userController(){
      UserModel userModel=tableService.getOneById(1, UserModel.class);
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String time=dateFormat.format(userModel.getCreateDate());
      System.out.println(time);
      return Results.success(userModel);
    }



    @PostMapping(value = "/save",desc = "用户新增")
    public JSONObject saveController(@RequestBody UserModel model){
        model.setCreateDate(new Date());
        UserModel userModel = tableService.saveOne(model,UserModel.class);

        return Results.success(userModel);
    }
}
